/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/24 23:22
  *
  * @file       pd_spi.h
  * @brief      Header file of SPI peripheral driver.
  *
  * @note       This file contains the SPI object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/24     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_SPI_H
#define JLC_SKY_SPI_H

#include "stm32f407xx.h"
#include "pd_gpio.h"
#include "drivers.h"

typedef struct SPIDef SPI;

struct SPIDef {

    GPIO **ssel;  // Slave Select
    uint8_t sselSize;   // Slave Select line size

    GPIO *sclk;  // Clock
    GPIO *mosi;  // Master Output Slave Input
    GPIO *miso;  // Master Input Slave Output

    void (*init)(SPI *this);

    void (*start)(SPI *this, GPIO *ssel);

    uint8_t (*swapByte)(SPI *super, uint8_t dat);

    void (*stop)(SPI *this, GPIO *ssel);
};

extern const struct SPIClass {
    SPI *(*build)(GPIO **ssel, uint8_t sselSize, GPIO *sclk, GPIO *mosi, GPIO *miso);
} SPIBuilder;

#endif //JLC_SKY_SPI_H
